package com.zonda.sampleretrofit2.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

public final class NewsListItem3Layout extends NewsListItemBaseLayout {

  public final static float BIG_FOCUS_IMAGE_RATIO = 16 / 9f;

  private TextView mTitleView;
  private ImageView mFocusImageView;
  private NewsListTagView mNewsTagView;

  public NewsListItem3Layout(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int widthHint = MeasureSpec.getSize(widthMeasureSpec);
    measureChildWithMargins(mTitleView, widthMeasureSpec, 0, heightMeasureSpec, 0);
    LayoutParams focusParams = (LayoutParams) mFocusImageView.getLayoutParams();
    focusParams.topMargin = mTitleView.getMeasuredHeight();
    focusParams.height = (int) (widthHint / BIG_FOCUS_IMAGE_RATIO);
    measureChildWithMargins(mFocusImageView, widthMeasureSpec, 0, heightMeasureSpec, 0);
    LayoutParams tagParams = (LayoutParams) mNewsTagView.getLayoutParams();
    tagParams.topMargin = focusParams.topMargin + mFocusImageView.getMeasuredHeight();
    measureChildWithMargins(mNewsTagView, widthMeasureSpec, 0, heightMeasureSpec, 0);
    int heightHint = tagParams.topMargin + mNewsTagView.getMeasuredHeight();
    setMeasuredDimension(resolveSize(widthHint, widthMeasureSpec),
        resolveSize(heightHint, heightMeasureSpec));
  }

  @Override
  void onInitChildView() {
    if(getChildCount() != 3){
      return;
    }
    mTitleView = (TextView) getChildAt(0);
    mFocusImageView = (ImageView) getChildAt(1);
    mNewsTagView = (NewsListTagView) getChildAt(2);
  }


}


























